home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MATH.SWG / 0046_Derive PI in Pascal.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  1KB  |  61 lines

  1. {
  2. BEN CURTIS
  3.  
  4. Here is a Program that I have written to derive Pi.  The formula is
  5. 4 - 4/3 + 4/5 - 4/7 + 4/9... ad infinitum.  Unfortunately, I can only get
  6. 14 decimal places using TP 6.  if there is a way For me to be able to get
  7. more than 14 decimal places, please let me know.
  8.  
  9. NB: Program Modified by Kerry Sokalsky to increase speed by over 40% -
  10.     I'm sure tons more can be done to speed this up even more.
  11. }
  12.  
  13. {$N+}
  14.  
  15. Uses
  16.   Dos, Crt;
  17.  
  18. Var
  19.   sum   : Real;
  20.   x, d,
  21.   Count : LongInt;
  22.   Odd   : Boolean;
  23.  
  24. begin
  25.   x   := 3;
  26.   d   := 4;
  27.   Sum := 4;
  28.   Odd := True;
  29.   Count := 0;
  30.  
  31.   Writeln(#13#10, 'Iteration Value', #13#10);
  32.  
  33.   ClrScr;
  34.  
  35.   Repeat
  36.     Inc(Count);
  37.     if Odd then
  38.       Sum := Sum - d/x
  39.     else
  40.       Sum := Sum + d/x;
  41.     Inc(x, 2);
  42.  
  43.     Odd := (Not Odd);
  44.  
  45.     GotoXY(1, 3);
  46.     Write(Count);
  47.     GotoXY(12, 3);
  48.     Write(Sum : 0 : 7);
  49.   Until KeyPressed;
  50.  
  51. end.
  52.  
  53. {
  54.         I have to warn you, it took me two hours to get a definite answer
  55. for 6 decimal places on my 486sx25.  I guess it would be faster on a dx.
  56. I'll run it on a 486dx2/66 on Tuesday and see if I can get it out to 14
  57. decimal places.  It takes about 135000 iterations to get 4 decimal places.
  58. Again, please let me know if you know of a way to get more than 14 decimal
  59. places -- I would love to get this sucker out to more. :)
  60. }
  61.